package com.prototype.prototypepattern.shallow;

import com.prototype.prototypepattern.shallow.impl.ConcretePrototypeA;
import java.util.ArrayList;
import java.util.List;

//@SpringBootApplication
public class PrototyPepatternApplication {

    /**
     *  浅克隆
     * @param args
     */
    public static void main(String[] args) {
        // 创建一个具体的需要克隆的对象
        ConcretePrototypeA concretePrototype = new ConcretePrototypeA();
        // 填充属性，方便测试
        concretePrototype.setAge(18);
        concretePrototype.setName("prototype");
        List list = new ArrayList<String>();
        list.add("123");
        list.add("321");
        concretePrototype.setHobbies(list);
        System.out.println(concretePrototype);
        System.out.println(concretePrototype.getHobbies().size());
        System.out.println(concretePrototype.getAge());
        System.out.println(concretePrototype.getName());

        // 创建 Client 对象，准备开始克隆
        Client client = new Client(concretePrototype);
        ConcretePrototypeA concretePrototypeClone = (ConcretePrototypeA) client.startClone(concretePrototype);
        System.out.println(concretePrototypeClone);
        System.out.println("克隆对象中的引用类型地址值：" + concretePrototypeClone.getHobbies());
        System.out.println("原对象中的引用类型地址值：" + concretePrototype.getHobbies());
        System.out.println(concretePrototypeClone.getHobbies().size());
        System.out.println(concretePrototypeClone.getAge());
        System.out.println(concretePrototypeClone.getName());

        System.out.println("对象地址比较："+(concretePrototypeClone.getHobbies() ==
                concretePrototype.getHobbies()));
    }

}
